﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IAlarm;

namespace TestEventReader
{
    public partial class Form1 : Form
    {
        AlarmManager.FileAlarmReader alarmReader = new AlarmManager.FileAlarmReader();
        public Form1()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GroupInfo[] groups = alarmReader.ReadGroups("计算机学院", "楼顶大镜头1", DateTime.Now);

            foreach (GroupInfo item in groups)
            {
                listBox1.Items.Add(item);
            }
        }

        GroupInfo currentGroup = null;
        List<Bitmap> images = new List<Bitmap>();
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            lock (this)
            {
                if (listBox1.SelectedItem != null && currentGroup != listBox1.SelectedItem)
                {
                    if (currentGroup != null)
                    {
                        images.Clear();
                    }

                    this.currentGroup = listBox1.SelectedItem as GroupInfo;

                }
            }
        }

        int index = 0;
        protected override void OnPaint(PaintEventArgs e)
        {
            lock (this)
            {
                try
                {
                    if (images.Count > 0)
                    {
                        if (index > images.Count) index = 0;

                        e.Graphics.DrawImage(images[index++], 0, 0);

                        index %= images.Count;
                    }
                }
                catch
                {
                    
                    throw;
                }
                
            }

            base.OnPaint(e);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            this.Invalidate();

        }
    }
}
